﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Model;
using SerialPortBll;

namespace 串口调试助手
{
    public partial class AddGroupFrm : Form
    {
        public AddGroupFrm()
        {
            InitializeComponent();
        }

        public event Action<WorkGroup> OnAddGrouped;

        private void radButtonCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void radButtonSave_Click(object sender, EventArgs e)
        {
            if (String.IsNullOrWhiteSpace(textBox1.Text))
            {
                MessageBox.Show("分组名称不能为空！", "温馨提示", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }

            WorkGroup tObj = WorkGroupBMO.selectObjByName(textBox1.Text);
            if (tObj != null)
            {
                MessageBox.Show("分组名称已存在，请重命名！", "名称重复", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                return;
            }
            WorkGroup obj = new WorkGroup();
            obj.Group_name = textBox1.Text.Trim();
            obj.Notes = richTextBox1.Text.Trim();
            if (WorkGroupBMO.save(obj) > 0)
            {                
                if (null != OnAddGrouped)
                {
                    OnAddGrouped(obj);
                }
                this.Close();
            }
        }
    }
}
